package com.lemon.library.net.Interceptor;

import com.lemon.library.constants.PreferencesConstants;
import com.lemon.library.utils.PreferencesUtils;

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Http 请求公共参数
 */
public class CommonRequestInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        String ContentType = null;

        String token = PreferencesUtils.getString(PreferencesConstants.login_Token);
        Request.Builder header = originalRequest.newBuilder()
                .header("Accept", "application/json, text/plain, */*")
                .header("Cookie", "LtpaToken=" + token);
        Request requestWithHeader = header.build();
        if (originalRequest != null && originalRequest.body() != null && originalRequest.body().contentType() != null) {
            ContentType = originalRequest.body().contentType().toString();
        }

        return chain.proceed(requestWithHeader);
    }


}
